package cn.itcast.service.impl;

import cn.itcast.dao.MenuDao;
import cn.itcast.pojo.Menu;
import cn.itcast.pojo.Role;
import cn.itcast.service.MenuService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Set;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuDao menuDao;

    @Override
    public List<Menu> getMenus() {
        List<Menu> menus = menuDao.getMenus();
        for (Menu menu : menus) {
            Set<Role> roles = menuDao.getRoles(menu.getId());
            menu.setRoles(roles);
        }
        return menus;
    }
}
